<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>菜单管理</title>
    <link rel="stylesheet" href="../../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../css/public.css" media="all">
    <style>
        .layui-btn:not(.layui-btn-lg ):not(.layui-btn-sm):not(.layui-btn-xs) {
            height: 34px;
            line-height: 34px;
            padding: 0 8px;
        }
    </style>
</head>
<body>

<table id="menu-table" class="layui-table" lay-filter="menu-table"></table>

<!-- 操作列 -->
<script type="text/html" id="auth-state">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="select">选择</a>
</script>

<script src="../../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../../js/lay-config.js" charset="utf-8"></script>
<script>
    layui.use(['table', 'treetable'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        var treetable = layui.treetable;

        // 渲染表格
        layer.load(2);
        treetable.render({
            treeColIndex: 1,
            treeSpid: -1,
            treeIdName: 'pkId',
            treePidName: 'parentId',
            elem: '#menu-table',
            url: 'admin/rbac/menu/tree',
            page: false,
            cols: [[
                {type: 'numbers', hide: true},
                {field: 'displayName', minWidth: 200, title: '目录名称'},
                {templet: '#auth-state', width: 100, align: 'center', title: '选择'}
            ]],
            done: function () {
                layer.closeAll('loading');
            }
        });


        //监听工具条
        table.on('tool(menu-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'select') {
                window.parent.$("input[name='parentName").val(data.displayName);
                window.parent.$("input[name='parentId").val(data.pkId);
                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);
            }
        });
        $("div .layui-table-header").hide();
        treetable.foldAll('#menu-table');
    });
</script>
</body>
</html>